﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using DAO;

public partial class DangNhap : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ketquadn.Visible = false;

    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        String connectstring = ConfigurationManager.ConnectionStrings["I_Group_WebConnectionString"].ToString();
        SqlConnection sqlconnect = new SqlConnection(connectstring);
        sqlconnect.Open();

        string sql = "select Username from THANH_VIEN where Username = @user and Password = @pass";
        SqlCommand commandForCheckUser = new SqlCommand(sql, sqlconnect);
        commandForCheckUser.Parameters.AddWithValue("@user", txtUsername.Text);
        commandForCheckUser.Parameters.AddWithValue("@pass", ThanhVienDAO.Encrypt(txtPassword.Text, true));
        commandForCheckUser.CommandType = CommandType.Text;
        string userIdSuccess = Convert.ToString(commandForCheckUser.ExecuteScalar());
        if (userIdSuccess != "")
        {
            Session["UserOnline"] = userIdSuccess;
            Response.Redirect("~/Default.aspx");           
        }
        else
        {
            ketquadn.Visible = true;
            ketquadn.Text = "Tên người dùng hoặc mật khẩu bạn đã nhập là không đúng!";
        }
    }
}
